import request from "@/utils/request";
import type { spuListPrams,getSpuRes,BaseSaleAttrListModel , spuSaleAttrList,SpuImageList,SaveOrUpdateSpuApiParams} from "./model/spuModel";

enum Api{
  getSpuListUrl='/admin/product',
  getBaseSaleAttrListUrl = "/admin/product/baseSaleAttrList",
  saveSpuUrl = "/admin/product/saveSpuInfo",
  getSpuImageListUrl = "/admin/product/spuImageList",
  getSpuSaleAttrListUrl = "/admin/product/spuSaleAttrList",
  updateSpuUrl = "/admin/product/updateSpuInfo",
  delSpuUrl="/admin/product/deleteSpu"
}

export const getSpuListApi=({page,limit,category3Id}:spuListPrams)=>{
return  request.get<any,getSpuRes>(Api.getSpuListUrl+`/${page}/${limit}`,{
        params:{category3Id,}
})
}

export const  getBaseSaleAttrApi=()=>{
  return request.get<any,BaseSaleAttrListModel>(Api.getBaseSaleAttrListUrl)
}
//添加Spu
export const saveSpuApi = (data: SaveOrUpdateSpuApiParams) => {
  return request.post<any, null>(Api.saveSpuUrl, data);
};
//根据id获取图片列表
export const getSpuImageListApi = (id:number) => {
  return request.get<any, SpuImageList>(Api.getSpuImageListUrl+`/${id}`);
};
// 根据id获取销售属性列表
export const getSpuSaleAttrListApi = (id:number) => {
  return request.get<any, spuSaleAttrList>(Api.getSpuSaleAttrListUrl+`/${id}`);
};
//更新spu
export const updateSpuApi = (data: SaveOrUpdateSpuApiParams) => {
  return request.post<any, null>(Api.updateSpuUrl,data);
};
///admin/product/deleteSpu/{spuId}
export const delSpuUrlApi = (id:number) => {
  return request.delete<any, null>(Api.delSpuUrl+`/${id}`);
};